package com.rankeiot.platform.controller;

import com.rankeiot.core.anno.Auth;
import com.rankeiot.core.data.response.PageResp;
import com.rankeiot.core.data.response.Resp;
import com.rankeiot.core.inner.argumet.QueryPage;
import com.rankeiot.core.sqltoy.Sql;
import com.rankeiot.platform.PlatformMenu;
import com.rankeiot.platform.domain.OperationLog;
import lombok.RequiredArgsConstructor;
import org.sagacity.sqltoy.dao.SqlToyLazyDao;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Auth(PlatformMenu.USER_LOG)
@RequestMapping("userOperation")
@RestController
@RequiredArgsConstructor
public class UserOperationLogController {
    final SqlToyLazyDao dao;

    @PostMapping("list")
    public PageResp<OperationLog> list(QueryPage query) {

        Sql sql = Sql.select("*")
                .from(OperationLog.class)
                .filter()
                .like(OperationLog::getUser)
                .like(OperationLog::getOperate)
                .like(OperationLog::getOperateType)
                .orderByDesc(OperationLog::getCreateTime);

        return Resp.of(dao.findPageBySql(query.page(), sql.toString(), query.getParams(),OperationLog.class));
    }
    @GetMapping("detail")
    public Resp<OperationLog> detail(Long id) {
        OperationLog log=new OperationLog();
        log.setId(id);
        return Resp.of(dao.load(log));
    }
}
